#include <stdio.h>
#include <stdlib.h>

int get_num_digits(int n);
void print_num(int num_to_print, int size, int cur_row);
void print_pipe(int n, char flag);
void print_space(int n);
void print_dash(int n);

FILE *output;

int main(int argc, char **argv){
	char in_number[6];
	int i,j,first;
	int rows, size, in_num_digits;
	int in_digits[7];
	FILE *f = fopen("output.txt", "w+");
	output = stdout;
	
	first = 1;
	while(scanf("%d %s", &size, in_number)==2){
		if(!size) break;
		rows = 2*size+3;
		i = 0;

		while(in_number[i] != '\0')
			in_digits[i] = in_number[i++] - '0';
		in_num_digits = i;
		
		for(i = 0; i < rows; i++){
			for(j = 0; j < in_num_digits; j++){
				print_num(in_digits[j], size, i);
				if(j != in_num_digits -1) fprintf(output, " ");
			}
			fprintf(output, "\n");
		}
		fprintf(output, "\n");
	}
	
	return(0);
}

void print_dash(int n){
	fprintf(output, " ");
	while(n--)
		fprintf(output, "-");
	fprintf(output, " ");
}
void print_space(int n){
	while(n--)
		fprintf(output, " ");
}
void print_pipe(int n, char flag){
	switch(flag){
		case 'l':
			fprintf(output, "|");
			print_space(n+1);
			break;
		case 'r':
			print_space(n+1);
			fprintf(output, "|");
			break;
		case 'b':
			fprintf(output, "|");
			print_space(n);
			fprintf(output, "|");
			break;
		case 'n':
			print_space(n+2);
			break;
	}
}

void print_num(int num_to_print, int size, int cur_row){
	int is_dash = (cur_row == 0 || cur_row == 2*size+2 || cur_row == size+1);
	if(is_dash){
		switch(num_to_print){
			case 0:
				if(cur_row == size+1)
					print_space(size+2);
				else
					print_dash(size);
				break;
			case 1:
				print_space(size+2);
				break;
			case 2:
			case 3:
			case 5:
			case 6:
			case 8:
			case 9:
				print_dash(size);
				break;
			case 4:
				if(cur_row == size+1)
					print_dash(size);
				else
					print_space(size+2);
				break;
			case 7:
				if(cur_row == 0)
					print_dash(size);
				else
					print_space(size+2);
				break;
		}
	}else{
		switch(num_to_print){
			case 0:
			case 8:
				print_pipe(size, 'b');
				break;
			case 1:
				print_pipe(size, 'r');
				break;
			case 2:
				if(cur_row < size+1)
					print_pipe(size, 'r');
				else
					print_pipe(size, 'l');
				break;
			case 3:
			case 7:
				print_pipe(size, 'r');
				break;
			case 4:
				if(cur_row < size+1)
					print_pipe(size, 'b');
				else
					print_pipe(size, 'r');
				break;
			case 5:
				if(cur_row < size+1)
					print_pipe(size, 'l');
				else
					print_pipe(size, 'r');
				break;
			case 6:
				if(cur_row < size+1)
					print_pipe(size, 'l');
				else
					print_pipe(size, 'b');
				break;
			case 9:
				if(cur_row < size+1)
					print_pipe(size, 'b');
				else
					print_pipe(size, 'r');
				break;
		}
	}
}

int get_num_digits(int n){
	int num_digits = 1;
	while((n /= 10) > 1){
		num_digits++;
	}
	return(num_digits);
}
